﻿#pragma once
#include "../GameApp/ResourceManager.h"
#include "Camera.h"
#include "Sprite.h"

struct SDL_Renderer;

namespace engine
{
	namespace render
	{
		class Renderer
		{
		public:
			Renderer(SDL_Renderer* sdlRenderer, engine::resource::ResourceManager* resourceManager);
			void drawSprite(const Camera& camera, const Sprite& sprite, const glm::vec2& position,
				const glm::vec2& scale = {1.0f,1.0f}, double angle=0.0f); //绘制精灵
			void drawParallax(const Camera& camera, const Sprite& sprite, const glm::vec2& position, glm::vec2& scroll_factor,
				const glm::bvec2& repeat = {true,true},const glm::vec2 & scale = { 1.0f,1.0f }); //绘制考虑视差效果
			void drawUISprite(const Sprite& sprite, const glm::vec2& position,const std::optional<glm::vec2>& size=std::nullopt); //绘制UI精灵

			void present(); //呈现渲染内容
			void clearScreen(); //清除屏幕

			inline void setDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a=255); //设置绘制颜色
			inline void setDrawColorFloat(float r, float g, float b, float a=1.0f); //设置绘制颜色（浮点数）
			inline SDL_Renderer* getSDLRenderer() const; //获取SDL渲染器

		private:
			SDL_Renderer* m_sdlRenderer = nullptr; //SDL渲染器
			engine::resource::ResourceManager* m_resourceManager = nullptr; //资源管理器
			std::optional<SDL_FRect> getSpriteSrcRect(const Sprite& sprite); //获取精灵目标矩形
			bool isRectInViewport(const Camera& camera, const SDL_FRect& rect); //检查矩形是否在视口内
		};
	}
}